// 引入mongoose包
const mongoose = require('mongoose')

// 连接本地数据库
mongoose.connect('mongodb://127.0.0.1:27017/test_db')

// 导出连接成功/失败状态的函数
module.exports = (onSuccess, onError) => {
    // 连接成功的触发
    mongoose.connection.on('open', onSuccess)
    // 连接失败触发
    mongoose.connection.on('error', onError)
}